package com.example.distillapplication.ui.fragment.log;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.distillapplication.R;
import com.example.distillapplication.data.entity.UserInfo;
import com.example.distillapplication.databinding.FragmentDataBinding;
import com.example.distillapplication.ui.fragment.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class DataFragment extends BaseFragment {
    FragmentDataBinding fragmentDataBinding;
    Bundle bundle;
    List<UserInfo> userInfos = new ArrayList<>();

    public DataFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_data, container, false);
        fragmentDataBinding = FragmentDataBinding.bind(view);
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        bundle = getArguments();
        userInfos = mDataBaseViewModel.dataBaseRepository.getUserInfoById(bundle.getInt("userId"));
        UserInfo userInfo = userInfos.get(0);
        fragmentDataBinding.account.setText(userInfo.getUserAccount());
        fragmentDataBinding.username.setText(userInfo.getUserName());
        fragmentDataBinding.loginTime.setText(bundle.getString("loginTime"));
        fragmentDataBinding.logoutTime.setText(bundle.getString("logoutTime"));
        fragmentDataBinding.operationData.setText(bundle.getString("operationData"));
        fragmentDataBinding.operationData.setMovementMethod(ScrollingMovementMethod.getInstance());

        fragmentDataBinding.buttom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController controller = Navigation.findNavController(v);
                controller.navigate(R.id.action_dataFragment_to_logListFragment);
            }
        });
    }
}
